<?php

declare(strict_types=1);

namespace App\Request\Admin;

use Hyperf\Validation\Request\FormRequest;
use Hyperf\Validation\Rule;

class AdminUserSaveRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        $id = $this->route('id');
        if ($id) {
            $username = [
                'required',
                Rule::unique('admin_user','username')->ignore($id)
            ];
            $mobile = [
                'required',
                Rule::unique('admin_user','mobile')->ignore($id)
            ];
        }else{
            $username = [
                'required',
                Rule::unique('admin_user','username')
            ];
            $mobile = [
                'required',
                Rule::unique('admin_user','mobile')
            ];
        }
        return [
            'username' => $username,
            'password' => 'required',
            'mobile' => $mobile,
            'role_id' => 'required',
            'position' => 'required'
        ];
    }
}
